package com.sxy.web; /**
 * @author 宋鑫宇
 * @version 1.0
 */

import com.alibaba.fastjson.JSON;
import com.sxy.pojo.Brand;
import com.sxy.service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {
    //创建service层对象
    private BrandService brandService = new BrandService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用service方法查询所有
        List<Brand> brands = brandService.selectAll();
        //把对象转成JSON字符串数据
        String s = JSON.toJSONString(brands);
        //3.把JSON的数据响应到页面
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(s);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
